def is_prime(number: int) -> bool:
    for j in range(2, number):
        if number % j == 0:
            return False
    return True


num = input()
rez = []
for i in range(1, len(num)+1):
    for k in range(len(num)-i+1):
        rez.append(num[k:k+i])
rez.reverse()


for n in rez:
    if is_prime(int(n)):
        print(n)
        break
else:
    print(0)
